﻿using System;
using System.Collections;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {

            ArrayList al = new ArrayList() {"小明","小黄","海子","玫瑰","松狮",521,7788 };

           int index=al.IndexOf("海子");
            //查找元素
            if (index!=-1)
            {
                Console.WriteLine("集合中有");
            }
            else
            {
                Console.WriteLine("不存在");
            }

            //  打印集合中的元素
            foreach (var item in al)
            {
                Console.WriteLine(item);
            }




         //打印集合元素下标为偶数的元素   
            ArrayList newlist = new ArrayList();
            for (int i = 0; i < al.Count; i = i + 2)
            {
                newlist.Add(al[i]);
            }
            foreach (var item in newlist)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            int[] list =
            {
                857,45,89,12,34
            };
            int[] newlist2 =new int[list.Length];
            list.CopyTo(newlist2, 0);
            for (int i = 0; i < newlist2.Length; i=i+2)
            {
                Console.WriteLine("偶数下标的元素有："+newlist2[i]);
            }

            //在第五个元素后插入
            ArrayList insertList = new ArrayList() {857,"雷霆嘎巴","ZBC" };
            al.InsertRange(5, insertList);
            foreach (var item in al)
            {
                Console.Write(item+" ");
            }

            Console.WriteLine();
            //比较排序输出 
            Compart compart = new Compart();
            al.Sort(compart);
            foreach (var item in al)
            {
                Console.Write(item+" ");
            }
           
        }
    }
}
